home *** CD-ROM | disk | FTP | other *** search
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
-
- namespace TestCSharpAudioCDRipper
- {
- public struct RipList
- {
- public string FileName;
- public int TracNum;
-
- public RipList(int index)
- {
- TracNum = 0;
- FileName = "";
- }
- }
-
- /// <summary>
- /// Summary description for Form1.
- /// </summary>
- public class Form1 : System.Windows.Forms.Form
- {
- internal System.Windows.Forms.ListView lvTracks;
- internal System.Windows.Forms.ColumnHeader ColumnHeader1;
- internal System.Windows.Forms.ColumnHeader ColumnHeader2;
- internal System.Windows.Forms.Panel Panel1;
- internal System.Windows.Forms.TextBox txtAlbum;
- internal System.Windows.Forms.TextBox txtArtist;
- internal System.Windows.Forms.ComboBox cbDrive;
- internal System.Windows.Forms.ToolBar ToolBar1;
- internal System.Windows.Forms.ToolBarButton ToolBarButton10;
- internal System.Windows.Forms.ToolBarButton btnEject;
- internal System.Windows.Forms.ToolBarButton btnRefreshCD;
- internal System.Windows.Forms.ToolBarButton btnGetCDDB;
- internal System.Windows.Forms.ToolBarButton btnRipNow;
- internal System.Windows.Forms.ImageList ImageList1;
- private System.Windows.Forms.StatusBar statusBar1;
- private System.Windows.Forms.StatusBarPanel statusBarPanel4;
- private System.Windows.Forms.StatusBarPanel statusBarPanel1;
- private System.Windows.Forms.StatusBarPanel statusBarPanel2;
- private System.Windows.Forms.StatusBarPanel statusBarPanel3;
- private System.ComponentModel.IContainer components;
-
- public Form1()
- {
- //
- // Required for Windows Form Designer support
- //
- InitializeComponent();
-
- //
- // TODO: Add any constructor code after InitializeComponent call
- //
- }
- Form2 frmProgress;
-
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if (components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
-
- #region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
- this.lvTracks = new System.Windows.Forms.ListView();
- this.ColumnHeader1 = new System.Windows.Forms.ColumnHeader();
- this.ColumnHeader2 = new System.Windows.Forms.ColumnHeader();
- this.Panel1 = new System.Windows.Forms.Panel();
- this.txtAlbum = new System.Windows.Forms.TextBox();
- this.txtArtist = new System.Windows.Forms.TextBox();
- this.cbDrive = new System.Windows.Forms.ComboBox();
- this.ToolBar1 = new System.Windows.Forms.ToolBar();
- this.ToolBarButton10 = new System.Windows.Forms.ToolBarButton();
- this.btnEject = new System.Windows.Forms.ToolBarButton();
- this.btnRefreshCD = new System.Windows.Forms.ToolBarButton();
- this.btnGetCDDB = new System.Windows.Forms.ToolBarButton();
- this.btnRipNow = new System.Windows.Forms.ToolBarButton();
- this.ImageList1 = new System.Windows.Forms.ImageList(this.components);
- this.statusBar1 = new System.Windows.Forms.StatusBar();
- this.statusBarPanel4 = new System.Windows.Forms.StatusBarPanel();
- this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();
- this.statusBarPanel2 = new System.Windows.Forms.StatusBarPanel();
- this.statusBarPanel3 = new System.Windows.Forms.StatusBarPanel();
- this.Panel1.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel4)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel3)).BeginInit();
- this.SuspendLayout();
- //
- // lvTracks
- //
- this.lvTracks.CheckBoxes = true;
- this.lvTracks.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
- this.ColumnHeader1,
- this.ColumnHeader2});
- this.lvTracks.Dock = System.Windows.Forms.DockStyle.Fill;
- this.lvTracks.FullRowSelect = true;
- this.lvTracks.GridLines = true;
- this.lvTracks.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
- this.lvTracks.HideSelection = false;
- this.lvTracks.Location = new System.Drawing.Point(0, 97);
- this.lvTracks.Name = "lvTracks";
- this.lvTracks.Size = new System.Drawing.Size(534, 277);
- this.lvTracks.TabIndex = 6;
- this.lvTracks.View = System.Windows.Forms.View.Details;
- //
- // ColumnHeader1
- //
- this.ColumnHeader1.Text = "Track";
- this.ColumnHeader1.Width = 400;
- //
- // ColumnHeader2
- //
- this.ColumnHeader2.Text = "Duration";
- //
- // Panel1
- //
- this.Panel1.Controls.AddRange(new System.Windows.Forms.Control[] {
- this.txtAlbum,
- this.txtArtist,
- this.cbDrive});
- this.Panel1.Dock = System.Windows.Forms.DockStyle.Top;
- this.Panel1.Location = new System.Drawing.Point(0, 55);
- this.Panel1.Name = "Panel1";
- this.Panel1.Size = new System.Drawing.Size(534, 42);
- this.Panel1.TabIndex = 5;
- //
- // txtAlbum
- //
- this.txtAlbum.Dock = System.Windows.Forms.DockStyle.Fill;
- this.txtAlbum.Location = new System.Drawing.Point(0, 21);
- this.txtAlbum.Name = "txtAlbum";
- this.txtAlbum.Size = new System.Drawing.Size(238, 20);
- this.txtAlbum.TabIndex = 1;
- this.txtAlbum.Text = "";
- //
- // txtArtist
- //
- this.txtArtist.Dock = System.Windows.Forms.DockStyle.Right;
- this.txtArtist.Location = new System.Drawing.Point(238, 21);
- this.txtArtist.Name = "txtArtist";
- this.txtArtist.Size = new System.Drawing.Size(296, 20);
- this.txtArtist.TabIndex = 2;
- this.txtArtist.Text = "";
- //
- // cbDrive
- //
- this.cbDrive.Dock = System.Windows.Forms.DockStyle.Top;
- this.cbDrive.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.cbDrive.Name = "cbDrive";
- this.cbDrive.Size = new System.Drawing.Size(534, 21);
- this.cbDrive.TabIndex = 0;
- //
- // ToolBar1
- //
- this.ToolBar1.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
- this.ToolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
- this.ToolBarButton10,
- this.btnEject,
- this.btnRefreshCD,
- this.btnGetCDDB,
- this.btnRipNow});
- this.ToolBar1.DropDownArrows = true;
- this.ToolBar1.ImageList = this.ImageList1;
- this.ToolBar1.Name = "ToolBar1";
- this.ToolBar1.ShowToolTips = true;
- this.ToolBar1.Size = new System.Drawing.Size(534, 55);
- this.ToolBar1.TabIndex = 4;
- this.ToolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.ToolBar1_ButtonClick_1);
- //
- // ToolBarButton10
- //
- this.ToolBarButton10.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
- //
- // btnEject
- //
- this.btnEject.ImageIndex = 0;
- this.btnEject.Tag = "0";
- this.btnEject.Text = "Eject";
- //
- // btnRefreshCD
- //
- this.btnRefreshCD.ImageIndex = 1;
- this.btnRefreshCD.Tag = "1";
- this.btnRefreshCD.Text = "Refresh CD";
- //
- // btnGetCDDB
- //
- this.btnGetCDDB.ImageIndex = 2;
- this.btnGetCDDB.Tag = "2";
- this.btnGetCDDB.Text = "Get CDDB";
- //
- // btnRipNow
- //
- this.btnRipNow.ImageIndex = 3;
- this.btnRipNow.Tag = "3";
- this.btnRipNow.Text = "Rip Now";
- //
- // ImageList1
- //
- this.ImageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit;
- this.ImageList1.ImageSize = new System.Drawing.Size(32, 32);
- this.ImageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ImageList1.ImageStream")));
- this.ImageList1.TransparentColor = System.Drawing.Color.Transparent;
- //
- // statusBar1
- //
- this.statusBar1.Location = new System.Drawing.Point(0, 352);
- this.statusBar1.Name = "statusBar1";
- this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
- this.statusBarPanel4,
- this.statusBarPanel1,
- this.statusBarPanel2,
- this.statusBarPanel3});
- this.statusBar1.ShowPanels = true;
- this.statusBar1.Size = new System.Drawing.Size(534, 22);
- this.statusBar1.TabIndex = 7;
- this.statusBar1.Text = "statusBar1";
- //
- // statusBarPanel4
- //
- this.statusBarPanel4.Width = 50;
- //
- // statusBarPanel1
- //
- this.statusBarPanel1.Width = 150;
- //
- // statusBarPanel2
- //
- this.statusBarPanel2.Width = 150;
- //
- // statusBarPanel3
- //
- this.statusBarPanel3.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
- this.statusBarPanel3.Width = 168;
- //
- // Form1
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
- this.ClientSize = new System.Drawing.Size(534, 374);
- this.Controls.AddRange(new System.Windows.Forms.Control[] {
- this.statusBar1,
- this.lvTracks,
- this.Panel1,
- this.ToolBar1});
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
- this.Name = "Form1";
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.Text = "TestCSharpAudioCDRipper";
- this.Load += new System.EventHandler(this.Form1_Load);
- this.Panel1.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel4)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel3)).EndInit();
- this.ResumeLayout(false);
-
- }
- #endregion
-
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.Run(new Form1());
- }
-
- NCTDISCRIPPERLib.AudioCDRipperClass ripper;
- public bool CancelRip;
- public long RipCount, RipCurrent, cddbSource, mripModePreset, m_Format;
-
- private void Form1_Load(object sender, System.EventArgs e)
- {
- ripper = new NCTDISCRIPPERLib.AudioCDRipperClass();
-
- ripper.RipProgress += new NCTDISCRIPPERLib._IAudioCDRipperEvents_RipProgressEventHandler(this.AudioCDRipper1_RipProgress);
- ripper.CDDBQueryStatus += new NCTDISCRIPPERLib._IAudioCDRipperEvents_CDDBQueryStatusEventHandler(this.AudioCDRipper1_CDDBQueryStatus);
- ripper.MediaChange += new NCTDISCRIPPERLib._IAudioCDRipperEvents_MediaChangeEventHandler(this.AudioCDRipper1_MediaChange);
- ripper.RipRetry += new NCTDISCRIPPERLib._IAudioCDRipperEvents_RipRetryEventHandler(this.AudioCDRipper1_RipRetry);
-
- ripper.DriverOpen();
-
- cddbSource = 0;
- mripModePreset = 1;
- m_Format = 0;
-
- frmProgress = new Form2();
- frmProgress.form = this;
-
- RefreshCD();
- }
- private void RefreshCD()
- {
- statusBar1.Panels[0].Text = "RefreshCD";
- PLEnable(false);
- TBBtnEnable(false);
- ripper.Refresh(); //Re-read CD drive
- cbDrive.Items.Clear();
- for (int i = 1; i <= ripper.driveCount; i++)
- {
- ripper.driveNum = i;
- cbDrive.Items.Add("(" + ripper.driveLetter + ") " + ripper.driveName);
- }
- if (cbDrive.Items.Count > 0)
- {
- cbDrive.SelectedIndex = 0;
- cbDrive_SelectedIndexChanged(null, null);
- }
-
- ReloadInfo();
- statusBar1.Panels[0].Text = "Ready";
-
- switch (ripper.cdType)
- {
- case NCTDISCRIPPERLib.CDDiskTypeConstants.REDBOOK : statusBar1.Panels[1].Text = "CD-DA (Audio Disk)"; break;
- case NCTDISCRIPPERLib.CDDiskTypeConstants.YELLOWBOOK : statusBar1.Panels[1].Text = "Data CD"; break;
- case NCTDISCRIPPERLib.CDDiskTypeConstants.ORANGEBOOK : statusBar1.Panels[1].Text = "Data CD"; break;
- case NCTDISCRIPPERLib.CDDiskTypeConstants.GREENBOOK : statusBar1.Panels[1].Text = "CD-Interactive"; break;
- case NCTDISCRIPPERLib.CDDiskTypeConstants.BLUEBOOK : statusBar1.Panels[1].Text = "CD-Extra"; break;
- case NCTDISCRIPPERLib.CDDiskTypeConstants.UNRECOGNIZED : statusBar1.Panels[1].Text = "No Disk"; break;
- }
-
- statusBar1.Panels[2].Text = "CDDB Disk ID: " + ripper.cdID.ToString("X");
- }
-
- private string MyIntToString(int Number)
- {
- if (Number > 9) return Number.ToString();
- return "0" + Number.ToString();
- }
-
- private void ReloadInfo()
- {
- PLEnable(false);
- TBBtnEnable(false);
- ripper.GetCDDBInfo(NCTDISCRIPPERLib.CDDBSourceConstants.CDPLAYERINI);
- statusBar1.Panels[3].Text = "CDDB Status: IDLE";
- txtAlbum.Text = ripper.cddbInfoAlbum;
- txtArtist.Text = ripper.cddbInfoArtist;
-
- if (txtArtist.Text.Length < 1) txtArtist.Text = "Unknown Artist";
- if (txtAlbum.Text.Length < 1) txtAlbum.Text = "Unknown Album";
-
- lvTracks.BeginUpdate();
- lvTracks.Items.Clear();
-
- if (ripper.trackCount != 0)
- {
- for (int i = 1; i <= ripper.trackCount; i++)
- {
- ripper.trackNum = i;
- ListViewItem li;
- if (ripper.cddbInfoTitle.Length > 0)
- li = lvTracks.Items.Add(MyIntToString(i) + " " + ripper.cddbInfoTitle);
- else
- li = lvTracks.Items.Add("Track " + MyIntToString(i));
-
- li.Checked = true;
- int min = ripper.trackDuration / 60000;
- int sec = ripper.trackDuration / 1000 - min * 60;
- li.SubItems.Add(MyIntToString(min) + ":" + MyIntToString(sec));
- }
- ripper.trackNum = 1;
- lvTracks.Items[0].Focused = true;
- PLEnable(true);
- TBBtnEnable(true);
- }
- else
- {
- TBBtnEnable(true);
- btnGetCDDB.Enabled = false;
- btnRipNow.Enabled = false;
- PLEnable(false);
- }
-
- lvTracks.EndUpdate();
- }
-
-
- private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
- {
- ripper.DriverClose();
- frmProgress.Dispose();
- }
-
- private void PLEnable(bool Enable)
- {
- lvTracks.Enabled = Enable;
- }
-
- private void TBBtnEnable(bool Enable)
- {
- btnEject.Enabled = Enable;
- btnRefreshCD.Enabled = Enable;
- btnGetCDDB.Enabled = Enable;
- btnRipNow.Enabled = Enable;
- }
-
- private void RipNow()
- {
- PLEnable(false);
- TBBtnEnable(false);
- ArrayList Rip = new ArrayList();
- RipList gl;
-
- RipCount = 0;
- for (int i = 0; i < lvTracks.Items.Count; i++)
- {
- if (lvTracks.Items[i].Checked)
- {
- gl = new RipList();
- gl.TracNum = i + 1;
- gl.FileName = lvTracks.Items[i].Text;
- RipCount += 1;
- Rip.Add(gl);
- }
- }
- if (RipCount < 1)
- {
- MessageBox.Show("No files to rip.");
- PLEnable(true);
- TBBtnEnable(true);
- return;
- }
- Refresh();
- frmProgress.pb1.Value = 0;
- frmProgress.pb2.Value = 0;
- frmProgress.Show();
- frmProgress.Refresh();
- CancelRip = false;
- ripper.ripModePreset = (NCTDISCRIPPERLib.RipModePresetConstants)mripModePreset;
- for (int i = 1; i <= Rip.Count; i++)
- {
- if (CancelRip) break;
- RipCurrent = i;
- gl = (RipList)Rip[i-1];
- ripper.trackNum = gl.TracNum;
- frmProgress.FileName = gl.FileName + ".mp3";
- Application.DoEvents(); //Yields execution so that operating system could produce the other events
- ripper.SetFormatMP3(NCTDISCRIPPERLib.RipFrequencyConstants.FQ_44_KHZ, NCTDISCRIPPERLib.RipBitrateConstants.BR_128_KBPS, NCTDISCRIPPERLib.RipChannelsConstants.STEREO);
- frmProgress.pb1.Value = 0;
- ripper.RipTrackToMP3(gl.FileName);
- while(frmProgress.pb1.Value != 100)
- Application.DoEvents();
- }
- for (int i = 1; i<= Rip.Count; i++) Rip.Remove(i);
- frmProgress.Hide();
- PLEnable(true);
- TBBtnEnable(true);
- }
-
-
- private void AudioCDRipper1_CDDBQueryStatus(NCTDISCRIPPERLib.CDDBQueryStatusConstants status)
- {
- switch (status)
- {
- case NCTDISCRIPPERLib.CDDBQueryStatusConstants.QUERY :
- statusBar1.Panels[3].Text = "CDDB Status: QUERY";
- break;
- case NCTDISCRIPPERLib.CDDBQueryStatusConstants.PROCESSANSWER :
- statusBar1.Panels[3].Text = "CDDB Status: PROCESS ANSWER";
- break;
- }
- }
-
- private void AudioCDRipper1_RipRetry(int retryNum)
- {
- frmProgress.DrawTextMy("Read or Synch Error! Retry.");
- Application.DoEvents(); //Yields execution so that operating system could produce the other events
- if (CancelRip) ripper.StopRip();
- }
-
- private void AudioCDRipper1_RipProgress(int percent)
- {
- Application.DoEvents(); //Yields execution so that operating system could produce the other events
- frmProgress.DrawTextMy("");
- frmProgress.pb1.Value = percent;
- frmProgress.pb2.Value = (int)(((RipCurrent-1) * 100 + percent) / RipCount);
- Application.DoEvents();
- if (CancelRip) ripper.StopRip();
- }
-
- private void AudioCDRipper1_MediaChange()
- {
- RefreshCD();
- }
-
- private void cbDrive_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- ripper.driveNum = cbDrive.SelectedIndex + 1;
- }
-
- private void ToolBar1_ButtonClick_1(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
- {
- switch (e.Button.Tag.ToString())
- {
- case "0":
- ripper.Eject();
- break;
- case "1":
- RefreshCD();
- break;
- case "2":
- bool CDDBInfoEnabled = false;
- switch(cddbSource)
- {
- case 1 : CDDBInfoEnabled = ripper.GetCDDBInfo(NCTDISCRIPPERLib.CDDBSourceConstants.ONLINEDATABASE); break;
- case 2 : CDDBInfoEnabled = ripper.GetCDDBInfo(NCTDISCRIPPERLib.CDDBSourceConstants.CDPLAYERINI); break;
- case 3 : CDDBInfoEnabled = ripper.GetCDDBInfo(NCTDISCRIPPERLib.CDDBSourceConstants.ALL); break;
- }
-
- if (CDDBInfoEnabled)
- {
- txtAlbum.Text = ripper.cddbInfoAlbum;
- txtArtist.Text = ripper.cddbInfoArtist;
- ReloadInfo();
- }
- else
- MessageBox.Show("No CDDB Information available! Try other CDDB source.");
-
- statusBar1.Panels[3].Text = "CDDB Status: IDLE";
- break;
- case "3":
- RipNow();
- break;
- }
- }
-
-
- }
- }
-